require('../less/base.less');
var React = require('react');
var Main = require('./views/Main');
var Login = require('./views/Login');
var PopupManager = require('./controls/PopupManager');
window.Store = require('./utils/Store');


module.exports = React.createClass({
	getInitialState:function(){
		return {
			view: 'Login'  //
		};
	},
	componentWillMount: function(){

	},
	setView: function (view) {
		this.setState({
			view: view
		});
	},
	__onLoginSuccess: function(data){
		localStorage.setItem('LOGIN_SESSION', JSON.stringify(data.result));
		this.setState({ view: 'Main' });
	},
	__onLogout: function (){
		localStorage.removeItem('LOGIN_SESSION');
		this.setState({ view: 'Login' });
	},
	getView: function () {
		if(localStorage.getItem('LOGIN_SESSION')){
			this.state.view = 'Main';
		}
		switch (this.state.view) {
			case 'Login':
				return <Login onSubmitSuccess={this.__onLoginSuccess} />;
			case 'Main':
				return <Main onLogout={this.__onLogout} />;
		}
	},
	render:function(){
		return (
			<div className="app">
				{this.getView()}
				<PopupManager />
			</div>
		);
	}
});
